define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'report/index' + location.search,
                    add_url: 'report/add',
                    down_url: 'report/down',
                    edit_url: 'report/edit',
                    del_url: 'report/del',
                    multi_url: 'report/multi',
                    import_url: 'report/import',
                    table: 'detection',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                showToggle: false,
                search:false,
                showColumns: false,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'unit_name', title: __('Unit_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'phone', title: __('Phone'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'producer', title: __('Producer'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'producer_time',operate: false, title: __('Producer_time'),  addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'sample_name', title: __('样品名称'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'sample_num', title: __('样品数量'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'sample_type', title: __('样品类型'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'smple_time',operate: false, title: __('Smple_time'),addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'detection_time', title: __('Detection_time'),  addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'sample_name', title: __('样品名称'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'create_time',operate: false, title: __('Create_time'), addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status',operate: false, title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        // {field: 'unit_id', title: __('Unit_id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            table.on('post-body.bs.table',function(){
                $(".btn-editone").data("area",["1200px","600px"]);
            })
            // 为表格绑定事件
            Table.api.bindevent(table);
            $("#testButton").on('click', function (){
                var ids = Table.api.selectedids(table);
                Fast.config.openArea = ['800px','600px']; //设置弹窗宽高,注意这里是全局调整
                Fast.api.open($.fn.bootstrapTable.defaults.extend.down_url+"/ids/"+ids,'批量下载二维码');
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        down: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
